package com.thjk.bdf.preloan.service.controller;

import com.alibaba.fastjson.JSONObject;
import com.thjk.bdf.common.base.BasicResp;
import com.thjk.bdf.common.enmus.ServiceEnum;
import com.thjk.bdf.common.request.CreditNotifyRequest;
import com.thjk.bdf.preloan.service.domain.domainservice.CreditNotifyService;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/credit/")
public class CreditNotifyController {

    private static final Logger logger = LoggerFactory.getLogger(CreditNotifyController.class);

    @Autowired
    private CreditNotifyService creditNotifyService;

    @RequestMapping(value = "notify", method = RequestMethod.POST)
    public BasicResp invoiceAdmittance(@RequestBody CreditNotifyRequest request) {
    	if(null == request) {
    		return BasicResp.back(ServiceEnum.SERVICE_PARAMETER_ERROR.getCode(), ServiceEnum.SERVICE_PARAMETER_ERROR.getDesc());
    	}
        logger.info("大数授信过程通知,"+ServiceEnum.getRetValue(request.getEventType())+ "=参数:"+JSONObject.toJSONString(request));
        BasicResp resp = creditNotifyService.creditNotify(request);
        logger.info("大数授信过程通知,"+ServiceEnum.getRetValue(request.getEventType())+ "=返回:"+JSONObject.toJSONString(resp));
        return resp;
    }
}
